home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / site.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  18KB  |  576 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """Append module search paths for third-party packages to sys.path.
  5.  
  6. ****************************************************************
  7. * This module is automatically imported during initialization. *
  8. ****************************************************************
  9.  
  10. In earlier versions of Python (up to 1.5a3), scripts or modules that
  11. needed to use site-specific modules would place ``import site''
  12. somewhere near the top of their code.  Because of the automatic
  13. import, this is no longer necessary (but code that does it still
  14. works).
  15.  
  16. This will append site-specific paths to the module search path.  On
  17. Unix (including Mac OSX), it starts with sys.prefix and
  18. sys.exec_prefix (if different) and appends
  19. lib/python<version>/site-packages as well as lib/site-python.
  20. On other platforms (such as Windows), it tries each of the
  21. prefixes directly, as well as with lib/site-packages appended.  The
  22. resulting directories, if they exist, are appended to sys.path, and
  23. also inspected for path configuration files.
  24.  
  25. For Debian and derivatives, this sys.path is augmented with directories
  26. for packages distributed within the distribution. Local addons go
  27. into /usr/local/lib/python<version>/dist-packages, Debian addons
  28. install into /usr/{lib,share}/python<version>/dist-packages.
  29. /usr/lib/python<version>/site-packages is not used.
  30.  
  31. A path configuration file is a file whose name has the form
  32. <package>.pth; its contents are additional directories (one per line)
  33. to be added to sys.path.  Non-existing directories (or
  34. non-directories) are never added to sys.path; no directory is added to
  35. sys.path more than once.  Blank lines and lines beginning with
  36. '#' are skipped. Lines starting with 'import' are executed.
  37.  
  38. For example, suppose sys.prefix and sys.exec_prefix are set to
  39. /usr/local and there is a directory /usr/local/lib/python2.5/site-packages
  40. with three subdirectories, foo, bar and spam, and two path
  41. configuration files, foo.pth and bar.pth.  Assume foo.pth contains the
  42. following:
  43.  
  44.   # foo package configuration
  45.   foo
  46.   bar
  47.   bletch
  48.  
  49. and bar.pth contains:
  50.  
  51.   # bar package configuration
  52.   bar
  53.  
  54. Then the following directories are added to sys.path, in this order:
  55.  
  56.   /usr/local/lib/python2.5/site-packages/bar
  57.   /usr/local/lib/python2.5/site-packages/foo
  58.  
  59. Note that bletch is omitted because it doesn't exist; bar precedes foo
  60. because bar.pth comes alphabetically before foo.pth; and spam is
  61. omitted because it is not mentioned in either path configuration file.
  62.  
  63. After these path manipulations, an attempt is made to import a module
  64. named sitecustomize, which can perform arbitrary additional
  65. site-specific customizations.  If this import fails with an
  66. ImportError exception, it is silently ignored.
  67.  
  68. """
  69. import sys
  70. import os
  71. import __builtin__
  72. PREFIXES = [
  73.     sys.prefix,
  74.     sys.exec_prefix]
  75. ENABLE_USER_SITE = None
  76. USER_SITE = None
  77. USER_BASE = None
  78.  
  79. def makepath(*paths):
  80.     dir = os.path.abspath(os.path.join(*paths))
  81.     return (dir, os.path.normcase(dir))
  82.  
  83.  
  84. def abs__file__():
  85.     """Set all module' __file__ attribute to an absolute path"""
  86.     for m in sys.modules.values():
  87.         if hasattr(m, '__loader__'):
  88.             continue
  89.         
  90.         
  91.         try:
  92.             m.__file__ = os.path.abspath(m.__file__)
  93.         continue
  94.         except AttributeError:
  95.             continue
  96.             continue
  97.         
  98.  
  99.     
  100.  
  101.  
  102. def removeduppaths():
  103.     ''' Remove duplicate entries from sys.path along with making them
  104.     absolute'''
  105.     L = []
  106.     known_paths = set()
  107.     for dir in sys.path:
  108.         (dir, dircase) = makepath(dir)
  109.         if dircase not in known_paths:
  110.             L.append(dir)
  111.             known_paths.add(dircase)
  112.             continue
  113.     
  114.     sys.path[:] = L
  115.     return known_paths
  116.  
  117.  
  118. def _init_pathinfo():
  119.     '''Return a set containing all existing directory entries from sys.path'''
  120.     d = set()
  121.     for dir in sys.path:
  122.         
  123.         try:
  124.             if os.path.isdir(dir):
  125.                 (dir, dircase) = makepath(dir)
  126.                 d.add(dircase)
  127.         continue
  128.         except TypeError:
  129.             continue
  130.             continue
  131.         
  132.  
  133.     
  134.     return d
  135.  
  136.  
  137. def addpackage(sitedir, name, known_paths):
  138.     """Process a .pth file within the site-packages directory:
  139.        For each line in the file, either combine it with sitedir to a path
  140.        and add that to known_paths, or execute it if it starts with 'import '.
  141.     """
  142.     if known_paths is None:
  143.         _init_pathinfo()
  144.         reset = 1
  145.     else:
  146.         reset = 0
  147.     fullname = os.path.join(sitedir, name)
  148.     
  149.     try:
  150.         f = open(fullname, 'rU')
  151.     except IOError:
  152.         return None
  153.  
  154.     f.__enter__()
  155.     
  156.     try:
  157.         for line in f:
  158.             if line.startswith(('import ', 'import\t')):
  159.                 exec line
  160.                 continue
  161.             
  162.             line = line.rstrip()
  163.             (dir, dircase) = makepath(sitedir, line)
  164.             if dircase not in known_paths and os.path.exists(dir):
  165.                 sys.path.append(dir)
  166.                 known_paths.add(dircase)
  167.                 continue
  168.     finally:
  169.         pass
  170.  
  171.     return known_paths
  172.  
  173.  
  174. def addsitedir(sitedir, known_paths = None):
  175.     """Add 'sitedir' argument to sys.path if missing and handle .pth files in
  176.     'sitedir'"""
  177.     if known_paths is None:
  178.         known_paths = _init_pathinfo()
  179.         reset = 1
  180.     else:
  181.         reset = 0
  182.     (sitedir, sitedircase) = makepath(sitedir)
  183.     if sitedircase not in known_paths:
  184.         sys.path.append(sitedir)
  185.     
  186.     
  187.     try:
  188.         names = os.listdir(sitedir)
  189.     except os.error:
  190.         return None
  191.  
  192.     dotpth = os.extsep + 'pth'
  193.     names = _[1]
  194.     for name in sorted(names):
  195.         addpackage(sitedir, name, known_paths)
  196.     
  197.     return known_paths
  198.  
  199.  
  200. def check_enableusersite():
  201.     '''Check if user site directory is safe for inclusion
  202.  
  203.     The function tests for the command line flag (including environment var),
  204.     process uid/gid equal to effective uid/gid.
  205.  
  206.     None: Disabled for security reasons
  207.     False: Disabled by user (command line option)
  208.     True: Safe and enabled
  209.     '''
  210.     if sys.flags.no_user_site:
  211.         return False
  212.     return True
  213.  
  214.  
  215. def addusersitepackages(known_paths):
  216.     '''Add a per user site-package to sys.path
  217.  
  218.     Each user has its own python directory with site-packages in the
  219.     home directory.
  220.  
  221.     USER_BASE is the root directory for all Python versions
  222.  
  223.     USER_SITE is the user specific site-packages directory
  224.  
  225.     USER_SITE/.. can be used for data.
  226.     '''
  227.     global USER_BASE, USER_SITE, USER_BASE, USER_SITE
  228.     env_base = os.environ.get('PYTHONUSERBASE', None)
  229.     
  230.     def joinuser(*args):
  231.         return os.path.expanduser(os.path.join(*args))
  232.  
  233.     if os.name == 'nt':
  234.         if not os.environ.get('APPDATA'):
  235.             pass
  236.         base = '~'
  237.         USER_BASE = None if env_base else joinuser(base, 'Python')
  238.         USER_SITE = os.path.join(USER_BASE, 'Python' + sys.version[0] + sys.version[2], 'site-packages')
  239.     elif env_base:
  240.         pass
  241.     
  242.     USER_BASE = joinuser('~', '.local')
  243.     USER_SITE = os.path.join(USER_BASE, 'lib', 'python' + sys.version[:3], 'site-packages')
  244.     if ENABLE_USER_SITE and os.path.isdir(USER_SITE):
  245.         addsitedir(USER_SITE, known_paths)
  246.     
  247.     if ENABLE_USER_SITE:
  248.         for dist_libdir in ('lib', 'local/lib'):
  249.             user_site = os.path.join(USER_BASE, dist_libdir, 'python' + sys.version[:3], 'dist-packages')
  250.             if os.path.isdir(user_site):
  251.                 addsitedir(user_site, known_paths)
  252.                 continue
  253.         
  254.     
  255.     return known_paths
  256.  
  257.  
  258. def addsitepackages(known_paths):
  259.     '''Add site-packages (and possibly site-python) to sys.path'''
  260.     sitedirs = []
  261.     seen = []
  262.     for prefix in PREFIXES:
  263.         if not prefix or prefix in seen:
  264.             continue
  265.         
  266.         seen.append(prefix)
  267.         if sys.platform in ('os2emx', 'riscos'):
  268.             sitedirs.append(os.path.join(prefix, 'Lib', 'site-packages'))
  269.         elif os.sep == '/':
  270.             sitedirs.append(os.path.join(prefix, 'lib', 'python' + sys.version[:3], 'dist-packages'))
  271.             sitedirs.append(os.path.join(prefix, 'local/lib', 'python' + sys.version[:3], 'dist-packages'))
  272.             sitedirs.append(os.path.join(prefix, 'lib', 'dist-python'))
  273.         else:
  274.             sitedirs.append(prefix)
  275.             sitedirs.append(os.path.join(prefix, 'lib', 'site-packages'))
  276.         if sys.platform == 'darwin':
  277.             if 'Python.framework' in prefix:
  278.                 sitedirs.append(os.path.expanduser(os.path.join('~', 'Library', 'Python', sys.version[:3], 'site-packages')))
  279.             
  280.         'Python.framework' in prefix
  281.     
  282.     for sitedir in sitedirs:
  283.         if os.path.isdir(sitedir):
  284.             addsitedir(sitedir, known_paths)
  285.             continue
  286.     
  287.     return known_paths
  288.  
  289.  
  290. def setBEGINLIBPATH():
  291.     '''The OS/2 EMX port has optional extension modules that do double duty
  292.     as DLLs (and must use the .DLL file extension) for other extensions.
  293.     The library search path needs to be amended so these will be found
  294.     during module import.  Use BEGINLIBPATH so that these are at the start
  295.     of the library search path.
  296.  
  297.     '''
  298.     dllpath = os.path.join(sys.prefix, 'Lib', 'lib-dynload')
  299.     libpath = os.environ['BEGINLIBPATH'].split(';')
  300.     if libpath[-1]:
  301.         libpath.append(dllpath)
  302.     else:
  303.         libpath[-1] = dllpath
  304.     os.environ['BEGINLIBPATH'] = ';'.join(libpath)
  305.  
  306.  
  307. def setquit():
  308.     """Define new built-ins 'quit' and 'exit'.
  309.     These are simply strings that display a hint on how to exit.
  310.  
  311.     """
  312.     if os.sep == ':':
  313.         eof = 'Cmd-Q'
  314.     elif os.sep == '\\':
  315.         eof = 'Ctrl-Z plus Return'
  316.     else:
  317.         eof = 'Ctrl-D (i.e. EOF)'
  318.     
  319.     class Quitter((object,)):
  320.         
  321.         def __init__(self, name):
  322.             self.name = name
  323.  
  324.         
  325.         def __repr__(self):
  326.             return 'Use %s() or %s to exit' % (self.name, eof)
  327.  
  328.         
  329.         def __call__(self, code = None):
  330.             
  331.             try:
  332.                 sys.stdin.close()
  333.             except:
  334.                 pass
  335.  
  336.             raise SystemExit(code)
  337.  
  338.  
  339.     __builtin__.quit = Quitter('quit')
  340.     __builtin__.exit = Quitter('exit')
  341.  
  342.  
  343. class _Printer(object):
  344.     '''interactive prompt objects for printing the license text, a list of
  345.     contributors and the copyright notice.'''
  346.     MAXLINES = 23
  347.     
  348.     def __init__(self, name, data, files = (), dirs = ()):
  349.         self._Printer__name = name
  350.         self._Printer__data = data
  351.         self._Printer__files = files
  352.         self._Printer__dirs = dirs
  353.         self._Printer__lines = None
  354.  
  355.     
  356.     def _Printer__setup(self):
  357.         if self._Printer__lines:
  358.             return None
  359.         data = None
  360.         for dir in self._Printer__dirs:
  361.             for filename in self._Printer__files:
  362.                 filename = os.path.join(dir, filename)
  363.                 
  364.                 try:
  365.                     fp = file(filename, 'rU')
  366.                     data = fp.read()
  367.                     fp.close()
  368.                 continue
  369.                 except IOError:
  370.                     self._Printer__lines
  371.                     self._Printer__lines
  372.                     continue
  373.                 
  374.  
  375.             
  376.             if data:
  377.                 break
  378.                 continue
  379.             self._Printer__lines<EXCEPTION MATCH>IOError
  380.         
  381.         self._Printer__lines = data.split('\n')
  382.         self._Printer__linecnt = len(self._Printer__lines)
  383.  
  384.     
  385.     def __repr__(self):
  386.         self._Printer__setup()
  387.         if len(self._Printer__lines) <= self.MAXLINES:
  388.             return '\n'.join(self._Printer__lines)
  389.         return 'Type %s() to see the full %s text' % (self._Printer__name,) * 2
  390.  
  391.     
  392.     def __call__(self):
  393.         self._Printer__setup()
  394.         prompt = 'Hit Return for more, or q (and Return) to quit: '
  395.         lineno = 0
  396.         while None:
  397.             
  398.             try:
  399.                 for i in range(lineno, lineno + self.MAXLINES):
  400.                     print self._Printer__lines[i]
  401.             except IndexError:
  402.                 break
  403.                 continue
  404.  
  405.             lineno += self.MAXLINES
  406.             key = None
  407.             while key is None:
  408.                 key = raw_input(prompt)
  409.                 if key not in ('', 'q'):
  410.                     key = None
  411.                     continue
  412.             if key == 'q':
  413.                 break
  414.                 continue
  415.             continue
  416.             return None
  417.  
  418.  
  419.  
  420. def setcopyright():
  421.     """Set 'copyright' and 'credits' in __builtin__"""
  422.     __builtin__.copyright = _Printer('copyright', sys.copyright)
  423.     if sys.platform[:4] == 'java':
  424.         __builtin__.credits = _Printer('credits', 'Jython is maintained by the Jython developers (www.jython.org).')
  425.     else:
  426.         __builtin__.credits = _Printer('credits', '    Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands\n    for supporting Python development.  See www.python.org for more information.')
  427.     here = os.path.dirname(os.__file__)
  428.     __builtin__.license = _Printer('license', 'See http://www.python.org/%.3s/license.html' % sys.version, [
  429.         'LICENSE.txt',
  430.         'LICENSE'], [
  431.         os.path.join(here, os.pardir),
  432.         here,
  433.         os.curdir])
  434.  
  435.  
  436. class _Helper(object):
  437.     """Define the built-in 'help'.
  438.     This is a wrapper around pydoc.help (with a twist).
  439.  
  440.     """
  441.     
  442.     def __repr__(self):
  443.         return 'Type help() for interactive help, or help(object) for help about object.'
  444.  
  445.     
  446.     def __call__(self, *args, **kwds):
  447.         import pydoc as pydoc
  448.         return pydoc.help(*args, **kwds)
  449.  
  450.  
  451.  
  452. def sethelper():
  453.     __builtin__.help = _Helper()
  454.  
  455.  
  456. def aliasmbcs():
  457.     '''On Windows, some default encodings are not provided by Python,
  458.     while they are always available as "mbcs" in each locale. Make
  459.     them usable by aliasing to "mbcs" in such a case.'''
  460.     if sys.platform == 'win32':
  461.         import locale as locale
  462.         import codecs as codecs
  463.         enc = locale.getdefaultlocale()[1]
  464.         if enc.startswith('cp'):
  465.             
  466.             try:
  467.                 codecs.lookup(enc)
  468.             except LookupError:
  469.                 import encodings as encodings
  470.                 encodings._cache[enc] = encodings._unknown
  471.                 encodings.aliases.aliases[enc] = 'mbcs'
  472.             except:
  473.                 None<EXCEPTION MATCH>LookupError
  474.             
  475.  
  476.         None<EXCEPTION MATCH>LookupError
  477.     
  478.  
  479.  
  480. def setencoding():
  481.     """Set the string encoding used by the Unicode implementation.  The
  482.     default is 'ascii', but if you're willing to experiment, you can
  483.     change this."""
  484.     encoding = 'ascii'
  485.     if encoding != 'ascii':
  486.         sys.setdefaultencoding(encoding)
  487.     
  488.  
  489.  
  490. def execsitecustomize():
  491.     '''Run custom site specific code, if available.'''
  492.     
  493.     try:
  494.         import sitecustomize as sitecustomize
  495.     except ImportError:
  496.         pass
  497.  
  498.  
  499.  
  500. def execusercustomize():
  501.     '''Run custom user specific code, if available.'''
  502.     
  503.     try:
  504.         import usercustomize as usercustomize
  505.     except ImportError:
  506.         pass
  507.  
  508.  
  509.  
  510. def main():
  511.     global ENABLE_USER_SITE
  512.     abs__file__()
  513.     known_paths = removeduppaths()
  514.     if ENABLE_USER_SITE is None:
  515.         ENABLE_USER_SITE = check_enableusersite()
  516.     
  517.     known_paths = addusersitepackages(known_paths)
  518.     known_paths = addsitepackages(known_paths)
  519.     if sys.platform == 'os2emx':
  520.         setBEGINLIBPATH()
  521.     
  522.     setquit()
  523.     setcopyright()
  524.     sethelper()
  525.     aliasmbcs()
  526.     setencoding()
  527.     execsitecustomize()
  528.     if ENABLE_USER_SITE:
  529.         execusercustomize()
  530.     
  531.     if hasattr(sys, 'setdefaultencoding'):
  532.         del sys.setdefaultencoding
  533.     
  534.  
  535. main()
  536.  
  537. def _script():
  538.     help = "    %s [--user-base] [--user-site]\n\n    Without arguments print some useful information\n    With arguments print the value of USER_BASE and/or USER_SITE separated\n    by '%s'.\n\n    Exit codes with --user-base or --user-site:\n      0 - user site directory is enabled\n      1 - user site directory is disabled by user\n      2 - uses site directory is disabled by super user\n          or for security reasons\n     >2 - unknown error\n    "
  539.     args = sys.argv[1:]
  540.     if not args:
  541.         print 'sys.path = ['
  542.         for dir in sys.path:
  543.             print '    %r,' % (dir,)
  544.         
  545.         print ']'
  546.         print None % ('USER_BASE: %r (%s)', USER_BASE if os.path.isdir(USER_BASE) else "doesn't exist")
  547.         print None % ('USER_SITE: %r (%s)', USER_SITE if os.path.isdir(USER_SITE) else "doesn't exist")
  548.         print 'ENABLE_USER_SITE: %r' % ENABLE_USER_SITE
  549.         sys.exit(0)
  550.     
  551.     buffer = []
  552.     if '--user-base' in args:
  553.         buffer.append(USER_BASE)
  554.     
  555.     if '--user-site' in args:
  556.         buffer.append(USER_SITE)
  557.     
  558.     if buffer:
  559.         print os.pathsep.join(buffer)
  560.         if ENABLE_USER_SITE:
  561.             sys.exit(0)
  562.         elif ENABLE_USER_SITE is False:
  563.             sys.exit(1)
  564.         elif ENABLE_USER_SITE is None:
  565.             sys.exit(2)
  566.         else:
  567.             sys.exit(3)
  568.     else:
  569.         import textwrap as textwrap
  570.         print textwrap.dedent(help % (sys.argv[0], os.pathsep))
  571.         sys.exit(10)
  572.  
  573. if __name__ == '__main__':
  574.     _script()
  575.  
  576.